home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / netlog-1.02 / extract / timesub.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-30  |  1.5 KB  |  87 lines

  1. /*
  2.      extract - A network log processor
  3.      Copyright (C) 1993 Douglas Lee Schales, David K. Hess, David R. Safford
  4.  
  5.      Please see the file `COPYING' for the complete copyright notice.
  6.  
  7. timesub.c - 03/20/93
  8.  
  9. */
  10. #include <sys/types.h>
  11. #include <sys/time.h>
  12. #include "timesub.h"
  13.  
  14. extern time_t time(time_t *);
  15.  
  16. int
  17. getyear(void)
  18. {
  19.      time_t t;
  20.      struct tm *tmb;
  21.  
  22.      t = time(0);
  23.  
  24.      tmb = localtime(&t);
  25.  
  26.      return tmb->tm_year;
  27. }
  28.  
  29. unsigned long
  30. makedate(int month, int mday, int year)
  31. {
  32.      time_t t;
  33.      struct tm *tmb;
  34.      struct tm tmbuf;
  35.  
  36.      t = time(0);
  37.  
  38.      tmb = localtime(&t);
  39.      
  40.      tmbuf.tm_zone = 0;
  41.      tmbuf.tm_gmtoff = 0;
  42.      tmbuf.tm_sec = 0;
  43.      tmbuf.tm_min = 0;
  44.      tmbuf.tm_hour = 0;
  45.      tmbuf.tm_mday = mday;
  46.      tmbuf.tm_mon = month - 1;
  47.      tmbuf.tm_year = year-1900;
  48.      tmbuf.tm_wday = 0;
  49.      tmbuf.tm_yday = 0;
  50.      return timelocal(&tmbuf);
  51. }
  52.  
  53. unsigned long
  54. today(void)
  55. {
  56.      time_t t;
  57.      struct tm *tmb;
  58.      struct tm tmbuf;
  59.  
  60.      t = time(0);
  61.  
  62.      tmb = localtime(&t);
  63.      memcpy(&tmbuf, tmb, sizeof(struct tm));
  64.      tmbuf.tm_zone = 0;
  65.      tmbuf.tm_gmtoff = 0;
  66.      tmbuf.tm_sec = 0;
  67.      tmbuf.tm_min = 0;
  68.      tmbuf.tm_hour = 0;
  69.      return timelocal(&tmbuf);
  70. }
  71.  
  72. static
  73. int daycnts[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  74.      
  75. int
  76. validmday(int month, int mday, int year)
  77. {
  78.      int febdays = 28;
  79.  
  80.      if(month != 2)
  81.       return mday > 0 && mday <= daycnts[month-1];
  82.      if(!(year % 4) && (!(year % 100) || year % 400))
  83.       febdays = 29;
  84.  
  85.      return mday > 0 && mday <= febdays;
  86. }
  87.